/*
* @Author: Administrator
* @Date:   2018-09-09 21:25:26
* @Last Modified by:   Administrator
* @Last Modified time: 2018-09-11 19:30:54
*/
import axios from 'axios';
import { fromJS } from 'immutable';
import * as constants from './constants.js';
const getHomeData = (result) => ({
  type: constants.CHANGE_DATA,
  topicList: result.topicList,
  articelList: result.articelList,
  writerList: result.writerList
})

const getMoreData = (result,nextPage) => ({
   type: constants.GET_MORE_LIST,
   list: fromJS(result),
   nextPage
})

export const getHomeInfo = () => {
	return (dispatch) => {
		axios.get('/api/home.json').then((res) => {
      const result = res.data.data;
      const action = getHomeData(result);
      dispatch(action);
    }).catch((err) => {
      alert('获取数据错误')
    })
	}
}

export const getMoreList = (page) => {
  return (dispatch) => {
    axios.get('/api/homeList.json?page=' + page).then((res) => {
      const result = res.data.data;
      dispatch(getMoreData(result,page+1));
    })
  }
}
export const changeDataScroll = () => ({
  type: constants.CHANGE_SCROLL
});

export const changeDataScrolls = () => ({
  type: constants.CHANGE_SCROLLS
});